# NOTE: could be changed to use rubyzip rather than the unzip system command.
class Cbz < Archive

  protected
    def get_filenames
      unzip(["Z", "1"])
    end

    def get_file(full_path_in_archive, dest)
      unzip("j", full_path_in_archive, dest)
    end

  private
    def unzip(opts = nil, files = nil, destination = SCRATCH_DIR)
      files = [files].flatten.compact
      opts = [opts].flatten.compact
      opts_str = opts.collect {|o| "-#{o}"}.join(' ') 
      cmd = %Q[unzip #{opts_str} "#{path}" ]
      cmd << files.collect {|f| %Q["#{f}"]}.join(" ") + " " if files.any?
      cmd << "-d \"#{destination}\""
      run(cmd)
    end

end
